/*
 * Project Name spring-boot-tools
 * File Name MessageCommand
 * Package Name com.huxiaosu.tools.cmpp.enums
 * Create Time 2024/4/20
 * Create by name：liujie
 */
package com.huxiaosu.tools.cmpp.enums;

import com.huxiaosu.tools.cmpp.utils.Length;
import lombok.Getter;

/**
 * 短信命令代码标识 (command_id定义)
 *
 * @author liujie
 * @date 2024/4/20 10:12
 */
@Getter
public enum CommandId {

    /**
     * 请求连接
     */
    CMPP_CONNECT(0x00000001) {
        @Override
        public int getMsgLength() {
            return Length.HEADER + Length.Connect.SOURCE_ADDR + Length.Connect.AUTHENTICATOR_SOURCE + Length.VERSION +Length.TIMESTAMP;

        }
    },
    /**
     * 请求连接应答
     */
    CMPP_CONNECT_RESP(0x80000001) {
        @Override
        public int getMsgLength() {
            return Length.HEADER + Length.STATUS + Length.ConnectResp.AUTHENTICATOR_ISMG + Length.VERSION;
        }
    },
    /**
     * 终止连接
     */
    CMPP_TERMINATE(0x00000002) {
        @Override
        public int getMsgLength() {
            return Length.HEADER;
        }
    },
    /**
     * 终止连接应答
     */
    CMPP_TERMINATE_RESP(0x80000002) {
        @Override
        public int getMsgLength() {
            return Length.HEADER;
        }
    },
    /**
     * 提交短信
     */
    CMPP_SUBMIT(0x00000004) {
        @Override
        public int getMsgLength() {
            return 0;
        }
    },
    /**
     * 提交短信应答
     */
    CMPP_SUBMIT_RESP(0x80000004) {
        @Override
        public int getMsgLength() {
            return Length.HEADER + Length.SubmitResp.MSG_ID +  Length.SubmitResp.RESULT;
        }
    },
    /**
     * 短信下发
     */
    CMPP_DELIVER(0x00000005) {
        @Override
        public int getMsgLength() {
            return 0;
        }
    },
    /**
     * 下发短信应答
     */
    CMPP_DELIVER_RESP(0x80000005) {
        @Override
        public int getMsgLength() {
            return 0;
        }
    },
    /**
     * 发送短信状态查询
     */
    CMPP_QUERY(0x00000006) {
        @Override
        public int getMsgLength() {
            return 0;
        }
    },
    /**
     * 发送短信状态查询应答
     */
    CMPP_QUERY_RESP(0x80000006) {
        @Override
        public int getMsgLength() {
            return 0;
        }
    },
    /**
     * 删除短信
     */
    CMPP_CANCEL(0x00000007) {
        @Override
        public int getMsgLength() {
            return 0;
        }
    },
    /**
     * 删除短信应答
     */
    CMPP_CANCEL_RESP(0x80000007) {
        @Override
        public int getMsgLength() {
            return 0;
        }
    },
    /**
     * 激活测试
     */
    CMPP_ACTIVE_TEST_RESP(0x80000008) {
        @Override
        public int getMsgLength() {
            return 0;
        }
    },
    /**
     * 激活测试应答
     */
    CMPP_ACTIVE_TEST(0x00000008) {
        @Override
        public int getMsgLength() {
            return 0;
        }
    },
    /**
     * 消息前转
     */
    CMPP_FWD(0x00000009) {
        @Override
        public int getMsgLength() {
            return 0;
        }
    },
    /**
     * 消息前转应答
     */
    CMPP_FWD_RESP(0x80000009) {
        @Override
        public int getMsgLength() {
            return 0;
        }
    },
    /**
     * MT路由请求
     */
    CMPP_MT_ROUTE(0x00000010) {
        @Override
        public int getMsgLength() {
            return 0;
        }
    },
    /**
     * MT路由请求应答
     */
    CMPP_MT_ROUTE_RESP(0x80000010) {
        @Override
        public int getMsgLength() {
            return 0;
        }
    },
    /**
     * MO路由请求
     */
    CMPP_MO_ROUTE(0x00000011) {
        @Override
        public int getMsgLength() {
            return 0;
        }
    },
    /**
     * MO路由请求应答
     */
    CMPP_MO_ROUTE_RESP(0x80000011) {
        @Override
        public int getMsgLength() {
            return 0;
        }
    },
    /**
     * 获取MT路由请求
     */
    CMPP_GET_MT_ROUTE(0x00000012) {
        @Override
        public int getMsgLength() {
            return 0;
        }
    },
    /**
     * 获取MT路由请求应答
     */
    CMPP_GET_MT_ROUTE_RESP(0x80000012) {
        @Override
        public int getMsgLength() {
            return 0;
        }
    },
    /**
     * MT路由更新
     */
    CMPP_MT_ROUTE_UPDATE(0x00000013) {
        @Override
        public int getMsgLength() {
            return 0;
        }
    },
    /**
     * MT路由更新应答
     */
    CMPP_MT_ROUTE_UPDATE_RESP(0x80000013) {
        @Override
        public int getMsgLength() {
            return 0;
        }
    },
    /**
     * MO路由更新
     */
    CMPP_MO_ROUTE_UPDATE(0x00000014) {
        @Override
        public int getMsgLength() {
            return 0;
        }
    },
    /**
     * MO路由更新应答
     */
    CMPP_MO_ROUTE_UPDATE_RESP(0x80000014) {
        @Override
        public int getMsgLength() {
            return 0;
        }
    },
    /**
     * MT路由更新
     */
    CMPP_PUSH_MT_ROUTE_UPDATE(0x00000015) {
        @Override
        public int getMsgLength() {
            return 0;
        }
    },
    /**
     * MT路由更新应答
     */
    CMPP_PUSH_MT_ROUTE_UPDATE_RESP(0x80000015) {
        @Override
        public int getMsgLength() {
            return 0;
        }
    },
    /**
     * MO路由更新
     */
    CMPP_PUSH_MO_ROUTE_UPDATE(0x00000016) {
        @Override
        public int getMsgLength() {
            return 0;
        }
    },
    /**
     * MO路由更新应答
     */
    CMPP_PUSH_MO_ROUTE_UPDATE_RESP(0x80000016) {
        @Override
        public int getMsgLength() {
            return 0;
        }
    },
    /**
     * 获取MO路由请求
     */
    CMPP_GET_MO_ROUTE(0x00000017) {
        @Override
        public int getMsgLength() {
            return 0;
        }
    },
    /**
     * 获取MO路由请求应答
     */
    CMPP_GET_MO_ROUTE_RESP(0x80000017) {
        @Override
        public int getMsgLength() {
            return 0;
        }
    },;

    private final int command;

    CommandId(int command) {
        this.command = command;
    }

    public static CommandId getById(int id) {
        for (CommandId item : values()) {
            if (id == item.getCommand()) {
                return item;
            }
        }
        return CMPP_CONNECT;
    }

    /** 获取消息的长度 */
    public abstract int getMsgLength();

}
